<?php
require_once '../../../config.php';

require_once './config.php';
require_once './function.php';
$id = intval($req['id'])===0 ? 1 : intval($req['id']);
$url = pageURL();

/*
 * 分页
 */
if($req['pag']) {
	$total = get_total($comment['table'], $id, $foreign_key);
	$pag = intval($req['pag'])===0 ? 1 : intval($req['pag']);
	if($pag>$total) $pag = 1;
	
	$list = get_list($comment['table'], $foreign_key, $id, $pag, $comment['limit']);
	//D($list);
	$pager = pager($url, $total, $pag, $comment['limit']);
	
	echo json_encode(array('pager'=>$pager, 'tol'=>$total, 'list'=>$list));
	exit;
}else{
	/*
	 * 插入评论
	 */
	insert_msg($comment['table'], $comment['keyvalue'], $req['auth'], $comment['cookiename']);	
}

/*
 * 清空变量值以免对后续文件造成影响
 */
$comment = $foreign_key = $list = $pag = $total = $id = $url = null;
?>